<template>
  <div class="jobmore ct">
      <el-breadcrumb class="head-nav" :separator-icon="ArrowRight">
          <el-breadcrumb-item :to="{ path: '/yardhome', query: {yardId}  }">站院首页</el-breadcrumb-item>
          <el-breadcrumb-item >农事问答</el-breadcrumb-item>
        </el-breadcrumb>
        <div class="s-content" >
          <div class="s-search">
            <el-input
              v-model="input1"
              class="s-input"
            >
              <template #append>
                <div class="cp"  @click="search1">搜索</div>
              </template>
            </el-input>
            <div class="s-input-ti" @click="gonspost">提问</div>
          </div>
          <div class="s-detal item-content">
            <div class="new-info">
              <div class="info-item" @click="goDetail(item.forumId)" v-for="item in works.list">
                <div class="info-i-t">
                  <div class="i-l">{{ item.title }}</div>
                  <div class="i-r">{{ item.releaseTime.slice(0,11) }}</div>
                </div>
              </div>
            </div>
          </div>
          <div class="item-page">
            <el-pagination
            :current-page="works.page"
            :page-size="15"
            background
            layout="prev, pager, next, jumper"
            prev-text="上一页"
            next-text="下一页"
            :total="works.total"
            @current-change="getPageQuestionAnswer"
        />
          </div>
      </div>
  </div>
</template>
<script setup>
import { useRouter } from 'vue-router';
import { computed, reactive, ref } from 'vue';
import { pageQuestionAnswer, searchForum, listFirstType, listSecondaryType } from '@/api/home'
  const router = useRouter();
  const yardId = computed(() => router?.currentRoute?.value?.query.yardId)


  const search1 = () => {
    works.question = input1.value;
    getPageQuestionAnswer(0)
  }

  const input1 = ref('')
 const works = reactive({
    list: [],
    total: 0,
    page: 1,
    
  });
  const getPageQuestionAnswer = async(pageNum=1) => {
    const params = {
      params: {
        status: true,
        title: input1.value,
        courtyardId: yardId.value,
      },
      page: {
        pageSize: 15,
        pageNum,
      }
    }
    const ret = await searchForum(params)
    works.list = ret?.data?.list || [];
    works.total = ret?.data?.total;
    works.page = pageNum;

  }
  getPageQuestionAnswer()



  const goDetail = (id) => {
    router.push(`/yardnsqaDetail/${id}?yardId=${yardId.value}`)
  }

  const gonspost = () => {
    if(!localStorage.getItem('userInfo_keji')) {
			ElMessage.error('请先登录')
      return
    }
    router.push('/yardnsqaPost?yardId='+yardId.value)
  }
</script>
<style lang="scss" scoped>
.jobmore {
  flex: 1;
  width: 100%;
  padding: 0 10%;
  color: #777;
  background: url('../../assets/xiaoyuan/4.jpeg') no-repeat center center / cover;

  .head-nav {
    display: flex;
    align-items: center;
    font-size: 24px;
    padding: 40px 0 30px;
    }
  .s-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 1000px;
    width: 100%;
    font-size: 24px;
  }
  .s-search {
    display: flex;
    align-items: center;
    :deep(.s-input) {
      font-size: 20px;
      height: 50px;
      width: 50%;
      .el-input__wrapper {
        background-color: #fff;
        box-shadow: none;
      }
      .el-input-group__append {
        color: #fff;
        background-color: #068043;
        height: 100%;
        padding: 0 30px;
        border-radius: 5px;
        cursor: pointer;
      }
    }
    .s-input-ti {
      color: #fff;
      background-color: #068043;
      padding: 0 30px;
      border-radius: 5px;
      height: 50px;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-left: 30px;
      cursor: pointer;
    }
  }
  .s-detal {
    margin-top: 28px;
    flex: 1;
    overflow: hidden;
    background-color: #fff;
  }
  .item-content {
    padding-top: 5px;
    display: flex;
    flex-direction: column;
    .new-info {
      flex: 1;
      background-color: #fff;
      padding: 20px 40px;
      overflow: hidden;
      color: #777;
      .info-item {
        border-bottom: 2px solid #e5e5e5;
        cursor: pointer;
        &:last-child{
          border-bottom: 0 none;
        }
      }
      .info-i-t {
        font-size: 24px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 15px 0;
        .i-l {
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
        }
        .i-r {
          margin-left: 40px;
        }
      }
    }
  }
  .item-page {
      height: 160px;
      display: flex;
      align-items: center;
      justify-content: center;
      :deep(.el-pagination) {
        button, li {
          background-color: transparent;
          width: 50px;
          height: 50px;
          border: 2px solid #e5e5e5;
          border-radius: 5px;
          color: #777;
          font-size: 24px;
          font-weight: normal;
          margin-right: 30px;
        }
        button {
          border: 0 none;
        }
        .el-pagination__jump {
          color: #777;
          font-size: 26px;
        }
        .el-pagination__editor {
          min-width: 50px;
          min-height: 50px;
          font-size: 24px;
        }
        .el-input__wrapper {
          padding: 0;
        }
        .el-input__inner {
          color: #777 !important;
        }
      }
  }

}
</style>